/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Purchases.java
 *
 * Created on 2011-mar-10, 00:18:17
 */

package imat;

import se.chalmers.ait.dat215.project.IMatDataHandler;
import se.chalmers.ait.dat215.project.Order;
import se.chalmers.ait.dat215.project.ShoppingItem;

public class Purchases extends javax.swing.JPanel {

    /** Creates new form Purchases */
    public Purchases() {
        initComponents();
        displayPreviousPurchases();
    }

    public void displayPreviousPurchases()
    {
        listAreaPanel.removeAll();
        
        for(Order o : IMatDataHandler.getInstance().getOrders()){
            double temp=0;
            purchaseRow p = new purchaseRow();
            p.setOrderNumber(o.getOrderNumber());
            p.setDateLabel((o.getDate().getYear()+1900)+"-"+(o.getDate().getMonth()+1)+"-"+(o.getDate().getDay()+6));
            java.util.List<ShoppingItem> itemlist = o.getItems();
            for(ShoppingItem i : itemlist){
                temp=temp+i.getTotal();
            }
            p.setSumLabel(temp+"");
            p.setOrder(o);
            listAreaPanel.add(p);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        headerPanel21 = new imat.HeaderPanel2();
        listAreaPanel = new javax.swing.JPanel();

        setName("Form"); // NOI18N

        headerPanel21.setName("headerPanel21"); // NOI18N

        listAreaPanel.setName("listAreaPanel"); // NOI18N
        listAreaPanel.setLayout(new javax.swing.BoxLayout(listAreaPanel, javax.swing.BoxLayout.Y_AXIS));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(listAreaPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 796, Short.MAX_VALUE))
            .addComponent(headerPanel21, javax.swing.GroupLayout.DEFAULT_SIZE, 806, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(headerPanel21, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(listAreaPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 937, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private imat.HeaderPanel2 headerPanel21;
    private javax.swing.JPanel listAreaPanel;
    // End of variables declaration//GEN-END:variables

}
